# Vaccine Diplomacy

## Replicates tables in main text for experimental analysis

source("table_function.R")

# Tables 4 and 5: Effect of aggregate vaccine distribution information treatment on trust in foreign governments, scale and binary outcomes ----

diplomacy_long <-
  read.csv("vaccine_diplomacy_long.csv", encoding = "UTF-8")

diplomacy_wide <- read.csv("vaccine_diplomacy_wide.csv", encoding = "UTF-8")

outcome_vector <- c(
  "scale" = "",
  "binary" = "_binary"
)

## Panel A: Average Treatment Effect ----

lapply(1:length(outcome_vector), function(x)
  
  table_function(
    data_frames = list(
      diplomacy_long,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide
    ),
    outcomes = c(
      "Trust (Pooled)"        = paste0("country_post_trust",    outcome_vector[x]),
      "Trust (China)"         = paste0("trust_china_end_post",  outcome_vector[x]),
      "Trust (India)"         = paste0("trust_india_end_post",  outcome_vector[x]),
      "Trust (Russia)"        = paste0("trust_russia_end_post", outcome_vector[x]),
      "Trust (UK)"            = paste0("trust_uk_end_post",     outcome_vector[x]),
      "Trust (US)"            = paste0("trust_us_end_post",     outcome_vector[x])
    ),
    treatments = c(
      "Treated" = "treat_rank", 
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank"
    ),
    trust_covariates = c(
      "country_pre_trust",
      "trust_china_end_pre",
      "trust_india_end_pre",
      "trust_russia_end_pre",
      "trust_uk_end_pre",
      "trust_us_end_pre"
    ),
    fixed_effects_name = "exp_block",
    table_name = paste0("main_results_experiment_ATE_", names(outcome_vector[x]))
  )
)

## Panels B-D ----

het_effects_list <- list(c("rev_rank_reported_ties",
                           "rev_rank_doses_ties_china",
                           "rev_rank_doses_ties_india",
                           "rev_rank_doses_ties_russia",
                           "rev_rank_doses_ties_uk",
                           "rev_rank_doses_ties_us"),
                         c("percentage_reported",
                           "vax_china",
                           "vax_india",
                           "vax_russia",
                           "vax_uk",
                           "vax_us"),
                         c("actual_gte_prior",
                           "actual_gte_prior_china",
                           "actual_gte_prior_india",
                           "actual_gte_prior_russia",
                           "actual_gte_prior_uk",
                           "actual_gte_prior_us"))

names(het_effects_list) <- c("rank", "share", "actgteprior")

het_effects_list_names <- list("Reversed rank", "Share", "Reversed rank $\\geq$ Reversed prior")

lapply(1:length(outcome_vector), function(i)
  lapply(1:length(het_effects_list), function(j)
    
    table_function(
      data_frames = list(
        diplomacy_long,
        diplomacy_wide,
        diplomacy_wide,
        diplomacy_wide,
        diplomacy_wide,
        diplomacy_wide
      ),
      outcomes = c(
        "Trust (Pooled)"        = paste0("country_post_trust",    outcome_vector[i]),
        "Trust (China)"         = paste0("trust_china_end_post",  outcome_vector[i]),
        "Trust (India)"         = paste0("trust_india_end_post",  outcome_vector[i]),
        "Trust (Russia)"        = paste0("trust_russia_end_post", outcome_vector[i]),
        "Trust (UK)"            = paste0("trust_uk_end_post",     outcome_vector[i]),
        "Trust (US)"            = paste0("trust_us_end_post",     outcome_vector[i])
      ),
      treatments = c(
        "Treated" = "treat_rank", 
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank"
      ),
      trust_covariates = c(
        "country_pre_trust",
        "trust_china_end_pre",
        "trust_india_end_pre",
        "trust_russia_end_pre",
        "trust_uk_end_pre",
        "trust_us_end_pre"
      ),
      interaction_effects = list(het_effects_list[[j]]),
      interaction_effects_name = list(het_effects_list_names[[j]]),
      fixed_effects_name = "exp_block",
      table_name = paste0("main_results_experiment_", names(het_effects_list)[j], "_", names(outcome_vector[i]))
    )
  )
)

## Panel E: Heterogeneity by rank of vaccines received by the respondent's country and prior beliefs ----

lapply(1:length(outcome_vector), function(x)
  
  table_function(
    data_frames = list(
      diplomacy_long,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide
    ),
    outcomes = c(
      "Trust (Pooled)"        = paste0("country_post_trust",    outcome_vector[x]),
      "Trust (China)"         = paste0("trust_china_end_post",  outcome_vector[x]),
      "Trust (India)"         = paste0("trust_india_end_post",  outcome_vector[x]),
      "Trust (Russia)"        = paste0("trust_russia_end_post", outcome_vector[x]),
      "Trust (UK)"            = paste0("trust_uk_end_post",     outcome_vector[x]),
      "Trust (US)"            = paste0("trust_us_end_post",     outcome_vector[x])
    ),
    treatments = c(
      "Treated" = "treat_rank", 
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank"
    ),
    trust_covariates = c(
      "country_pre_trust",
      "trust_china_end_pre",
      "trust_india_end_pre",
      "trust_russia_end_pre",
      "trust_uk_end_pre",
      "trust_us_end_pre"
    ),
    interaction_effects = list(
      c("rev_rank_reported_ties",
        "rev_rank_doses_ties_china",
        "rev_rank_doses_ties_india",
        "rev_rank_doses_ties_russia",
        "rev_rank_doses_ties_uk",
        "rev_rank_doses_ties_us"),
      c("rev_rank_prior",
        "rev_prior_beliefs_china",
        "rev_prior_beliefs_india",
        "rev_prior_beliefs_russia",
        "rev_prior_beliefs_uk",
        "rev_prior_beliefs_us")  
    ),
    interaction_effects_name = list("Reversed Rank", "Reversed prior"),
    fixed_effects_name = "exp_block",
    table_name = paste0("main_results_experiment_rankprior_", names(outcome_vector[x]))
  )
)

# Table 6: The effect of the aggregate vaccine distribution information treatment on the perceived motivation of government of the country where the vaccine was developed for distributing vaccines ----
  
table_function(
  data_frames = list(
    diplomacy_long,
    diplomacy_long,
    diplomacy_long,
    diplomacy_long,
    diplomacy_long
  ),
  outcomes = c(
    "Stop COVID-19 Spread"          = "country_post_mechanisms_stopcovid",
    "Help respondent country"       = "country_post_mechanisms_help",
    "Increase support for sender"   = "country_post_mechanisms_support",
    "Increase dependence on sender" = "country_post_mechanisms_dependence",
    "Obtain economic profits"       = "country_post_mechanisms_economics"
  ), 
  treatments = c(
    "Treated" = "treat_rank", 
    "Treated" = "treat_rank",
    "Treated" = "treat_rank",
    "Treated" = "treat_rank",
    "Treated" = "treat_rank"
  ),
  trust_covariates = c(
    "country_pre_trust",
    "country_pre_trust",
    "country_pre_trust",
    "country_pre_trust",
    "country_pre_trust"
  ),
  interaction_effects = list(c("rev_rank_reported_ties",
                               "rev_rank_reported_ties",
                               "rev_rank_reported_ties",
                               "rev_rank_reported_ties",
                               "rev_rank_reported_ties")),
  interaction_effects_name = list("Reversed rank"),
  fixed_effects_name = "exp_block",
  table_name = "mechanism_effects_experimental_rank"
)

# Table 7: The pooled effect of the aggregate vaccine distribution information treatment on trust in foreign governments across public good-oriented and cynical respondents, outcome scale ----

## Note: only the pooled results are reported in the paper

## Panel A: Average Treatment Effect ----

subsamples <- c("publicgood_v_cynical",
                "cynical_v_publicgood")

lapply(1:length(outcome_vector), function(y)
  lapply(1:length(subsamples), function(i)
    table_function(
      data_frames = list(
        filter(diplomacy_long, get(paste0(subsamples[i])) == 1),
        filter(diplomacy_wide, get(paste0(subsamples[i], "_china")) == 1),
        filter(diplomacy_wide, get(paste0(subsamples[i], "_india")) == 1),
        filter(diplomacy_wide, get(paste0(subsamples[i], "_russia")) == 1),
        filter(diplomacy_wide, get(paste0(subsamples[i], "_uk")) == 1),
        filter(diplomacy_wide, get(paste0(subsamples[i], "_us")) == 1)
      ),
      outcomes = c(
        "Trust (Pooled)"        = paste0("country_post_trust",    outcome_vector[y]),
        "Trust (China)"         = paste0("trust_china_end_post",  outcome_vector[y]),
        "Trust (India)"         = paste0("trust_india_end_post",  outcome_vector[y]),
        "Trust (Russia)"        = paste0("trust_russia_end_post", outcome_vector[y]),
        "Trust (UK)"            = paste0("trust_uk_end_post",     outcome_vector[y]),
        "Trust (US)"            = paste0("trust_us_end_post",     outcome_vector[y])
      ),
      treatments = c(
        "Treated" = "treat_rank", 
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank"
      ),
      trust_covariates = c(
        "country_pre_trust",
        "trust_china_end_pre",
        "trust_india_end_pre",
        "trust_russia_end_pre",
        "trust_uk_end_pre",
        "trust_us_end_pre"
      ),
      fixed_effects_name = "exp_block",
      table_name = paste0("results_experiment_ATE_", names(outcome_vector[y]), "_", subsamples[i])
    )
  )
)

## Panels B-D ----

het_effects_list <- list(c("rev_rank_reported_ties",
                           "rev_rank_doses_ties_china",
                           "rev_rank_doses_ties_india",
                           "rev_rank_doses_ties_russia",
                           "rev_rank_doses_ties_uk",
                           "rev_rank_doses_ties_us"),
                         c("percentage_reported",
                           "vax_china",
                           "vax_india",
                           "vax_russia",
                           "vax_uk",
                           "vax_us"),
                         c("actual_gte_prior",
                           "actual_gte_prior_china",
                           "actual_gte_prior_india",
                           "actual_gte_prior_russia",
                           "actual_gte_prior_uk",
                           "actual_gte_prior_us"))

names(het_effects_list) <- c("rank", "share", "actgteprior")

het_effects_list_names <- list("Reversed rank", "Share", "Reversed rank $\\geq$ Reversed prior")

lapply(1:length(outcome_vector), function(y)
  lapply(1:length(subsamples), function(i)
    lapply(1:length(het_effects_list), function(j)
    
      table_function(
        data_frames = list(
          filter(diplomacy_long, get(paste0(subsamples[i])) == 1),
          filter(diplomacy_wide, get(paste0(subsamples[i], "_china")) == 1),
          filter(diplomacy_wide, get(paste0(subsamples[i], "_india")) == 1),
          filter(diplomacy_wide, get(paste0(subsamples[i], "_russia")) == 1),
          filter(diplomacy_wide, get(paste0(subsamples[i], "_uk")) == 1),
          filter(diplomacy_wide, get(paste0(subsamples[i], "_us")) == 1)
        ),
        outcomes = c(
          "Trust (Pooled)"        = paste0("country_post_trust",    outcome_vector[y]),
          "Trust (China)"         = paste0("trust_china_end_post",  outcome_vector[y]),
          "Trust (India)"         = paste0("trust_india_end_post",  outcome_vector[y]),
          "Trust (Russia)"        = paste0("trust_russia_end_post", outcome_vector[y]),
          "Trust (UK)"            = paste0("trust_uk_end_post",     outcome_vector[y]),
          "Trust (US)"            = paste0("trust_us_end_post",     outcome_vector[y])
        ),
        treatments = c(
          "Treated" = "treat_rank", 
          "Treated" = "treat_rank",
          "Treated" = "treat_rank",
          "Treated" = "treat_rank",
          "Treated" = "treat_rank",
          "Treated" = "treat_rank"
        ),
        trust_covariates = c(
          "country_pre_trust",
          "trust_china_end_pre",
          "trust_india_end_pre",
          "trust_russia_end_pre",
          "trust_uk_end_pre",
          "trust_us_end_pre"
        ),
        interaction_effects = list(het_effects_list[[j]]),
        interaction_effects_name = list(het_effects_list_names[[j]]),
        fixed_effects_name = "exp_block",
        table_name = paste0("results_experiment_", names(het_effects_list)[j], "_", names(outcome_vector[y]), "_", subsamples[i]))
    )
  )
)

## Panel E: Heterogeneity by rank of vaccines received by the respondent's country and prior beliefs ----

lapply(1:length(outcome_vector), function(y)
  lapply(1:length(subsamples), function(i)

    table_function(
      data_frames = list(
        filter(diplomacy_long, get(paste0(subsamples[i])) == 1),
        filter(diplomacy_wide, get(paste0(subsamples[i], "_china")) == 1),
        filter(diplomacy_wide, get(paste0(subsamples[i], "_india")) == 1),
        filter(diplomacy_wide, get(paste0(subsamples[i], "_russia")) == 1),
        filter(diplomacy_wide, get(paste0(subsamples[i], "_uk")) == 1),
        filter(diplomacy_wide, get(paste0(subsamples[i], "_us")) == 1)
      ),
      outcomes = c(
        "Trust (Pooled)"        = paste0("country_post_trust",    outcome_vector[y]),
        "Trust (China)"         = paste0("trust_china_end_post",  outcome_vector[y]),
        "Trust (India)"         = paste0("trust_india_end_post",  outcome_vector[y]),
        "Trust (Russia)"        = paste0("trust_russia_end_post", outcome_vector[y]),
        "Trust (UK)"            = paste0("trust_uk_end_post",     outcome_vector[y]),
        "Trust (US)"            = paste0("trust_us_end_post",     outcome_vector[y])
      ),
      treatments = c(
        "Treated" = "treat_rank", 
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank"
      ),
      trust_covariates = c(
        "country_pre_trust",
        "trust_china_end_pre",
        "trust_india_end_pre",
        "trust_russia_end_pre",
        "trust_uk_end_pre",
        "trust_us_end_pre"
      ),
      interaction_effects = list(
        c("rev_rank_reported_ties",
          "rev_rank_doses_ties_china",
          "rev_rank_doses_ties_india",
          "rev_rank_doses_ties_russia",
          "rev_rank_doses_ties_uk",
          "rev_rank_doses_ties_us"),
        c("rev_rank_prior",
          "rev_prior_beliefs_china",
          "rev_prior_beliefs_india",
          "rev_prior_beliefs_russia",
          "rev_prior_beliefs_uk",
          "rev_prior_beliefs_us")  
      ),
      interaction_effects_name = list("Reversed Rank", "Reversed prior"),
      fixed_effects_name = "exp_block",
      table_name = paste0("results_experiment_rankprior_", names(outcome_vector[y]), "_", subsamples[i])
    )
  )
)